package com.gh.netty.server.handler;

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

/**
 * @author hugx
 * @create 2018-09-29 17:38
 */
public class MyReadHandlerTwo extends ReplayingDecoder<Byte> {
    private static  final Logger log=Logger.getLogger(MyReadHandlerTwo.class);

    private List<Object> outTmp=new ArrayList<>();

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        super.channelReadComplete(ctx);
        log.info("===  channelReadComplete len: "+outTmp.size());
        outTmp.forEach(i->{
            log.info(i);
        });
        outTmp.clear();
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        log.info("=== decode "+out.stream().toString());
        out.add(in.readByte());
        outTmp.add(in.readByte());
    }


}
